//
//  NSArray+Extension.m
//  QMUI_TEST
//
//  Created by mac on 17/4/28.
//  Copyright © 2017年 Apple. All rights reserved.
//

#import "NSArray+Extension.h"

@implementation NSArray (Extension)
- (NSString *)descriptionWithLocale:(id)locale{
    return self.description.unicodeString;
}
-(NSMutableArray *)sortForKey:(NSString *)key{
    if (!self.count) {
        return @[].mutableCopy;
    }
    NSMutableArray *sortArray = @[].mutableCopy;
    NSMutableArray *newDataArray = @[].mutableCopy;
    id firstObj = self.firstObject;
   __block NSString * oldValue = [firstObj valueForKey:key];
//    [newDataArray addObject:firstObj];
    [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *newValue = [obj valueForKey:key];
        if ([newValue isEqualToString:oldValue]) {
            [newDataArray addObject:obj];
        }else{
            [sortArray addObject:newDataArray.copy];
            [newDataArray removeAllObjects];
            [newDataArray addObject:obj];
            oldValue = newValue;
            JSLog(@"stop %zd", stop);
        }
    }];
    [sortArray addObject:newDataArray];
    return sortArray;
}
@end
